package cn.itlaobing.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import cn.itlaobing.entity.Student;
import cn.itlaobing.entity.enums.Gender;
import cn.itlaobing.service.StudentService;
import cn.itlaobing.vo.PageRequest;
import cn.itlaobing.vo.Pageable;

@Controller("/students/home")
public class StudentHomeController extends BaseController {

	Log log = LogFactory.getLog(StudentHomeController.class);
	@Autowired
	private StudentService studentService;

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// List<Student> students=studentService.findAll();
		request.setAttribute("genders", Gender.values());
		// 取出分页请求参数
		PageRequest pr = (PageRequest) request.getAttribute(PageRequest.REQUEST_SCOPE_KEY);
		
		Pageable<Student> pageable = studentService.findPageable(pr);
		pageable.setBaseUrl(request.getServletPath());
		// 放到request范围
		request.setAttribute("pageable", pageable);
		toView("/students/index.jsp", request, response);
	}
}
